package com.wanxi.spring.cloud.team.service.impl;

import com.wanxi.spring.cloud.commons.api.CommonResult;
import com.wanxi.spring.cloud.team.mapper.SignMapper;
import com.wanxi.spring.cloud.team.model.Sign;
import com.wanxi.spring.cloud.team.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 蒋帆
 * @since 2020-12-21
 */
@Service
public class SignServiceImpl implements SignService {

    @Autowired(required = false)
    SignMapper signMapper;

    @Override
    public CommonResult addSignRecords(Map map) {
        String user_names = ((String) map.get("code_name")).replace("\"","");
        String status = ((String) map.get("sign_status")).replace("\"","");
        String late_times = ((String) map.get("late_time"));
        String[] user_name = user_names.substring(1,user_names.length()-1).split(",");
        String[] statu = status.substring(1,status.length()-1).split(",");
        String[] late_time = late_times.substring(1,late_times.length()-1).split(",");
        List<Sign> list = new ArrayList<>();
        for(int i=0;i<user_name.length;i++){
            Sign sign = new Sign();
            sign.setUser(user_name[i]);
            sign.setStatus(statu[i]);
            sign.setLateTime(late_time[i].replace("\"",""));
            list.add(sign);
        }
        System.out.println(list);
        int result = signMapper.addSignRecords(list);
        if (result>0)
            return CommonResult.success(result,"点到成功");
        else
            return CommonResult.failed();
    }

    @Override
    public CommonResult getSignRecords() {
        List<Sign> signs = signMapper.getSignRecords();
        return CommonResult.success(signs);
    }
}
